package org.demo.base.config;

import javax.inject.Inject;
import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

@Configuration
@ComponentScan({
	"org.demo.base.config",
	"org.demo.base.dao"
})
@PropertySource({
        "classpath:/datasource.properties",
})
public class BaseConfiguration {

    /* ---- Instance Variables ---- */
    Logger log = Logger.getLogger(getClass());

    @Inject
    private Environment environment;

    @Autowired
    protected DataSource dataSource = null;


    /* ---- Constructors ---- */
    public BaseConfiguration() {
        super();
        log.info("BaseConfiguration - demo-base");
    }

    /* ---- Configuration Beans ---- */


    @Bean
    public JdbcTemplate jdbcTemplate() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());
        return jdbcTemplate;
    }

    @Bean
    public DataSourceTransactionManager transactionManager() {
    	DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
    	return transactionManager;
    }

    /* ---- Getters and Setters ---- */

	public DataSource getDataSource() {
		return dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

}
